package com.qyhl.webtv.commonlib.utils.push;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.callback.NavCallback;
import com.alibaba.android.arouter.launcher.ARouter;
import com.alibaba.sdk.android.push.AndroidPopupActivity;
import com.google.gson.Gson;
import com.qyhl.webtv.commonlib.R;
import com.qyhl.webtv.commonlib.constant.ARouterPathConstant;
import com.qyhl.webtv.commonlib.entity.PushParametersBean;
import com.qyhl.webtv.commonlib.utils.eventbus.BusFactory;
import com.qyhl.webtv.commonlib.utils.eventbus.Event;

import java.util.Map;

/**
 * 阿里推送辅助弹窗
 */
public class PopupPushActivity extends AndroidPopupActivity {

    static final String TAG = "PopupPushActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_popup_push);
        Log.e("PopupPushActivity", "onCreate");

    }

    /**
     * 实现通知打开回调方法，获取通知相关信息
     *
     * @param title   标题
     * @param summary 内容
     * @param extMap  额外参数
     */
    @Override
    protected void onSysNoticeOpened(String title, String summary, Map<String, String> extMap) {
        Log.i(TAG, "onSysNoticeOpened");
        Log.i(TAG, "OnMiPushSysNoticeOpened, title: " + title + ", content: " + summary + ", extMap: " + extMap);
        Gson gson = new Gson();
        PushParametersBean pushData = gson.fromJson(gson.toJson(extMap), PushParametersBean.class);
        ARouter.getInstance().build(ARouterPathConstant.HOME_ACTIVITY)
                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
                .withSerializable("msg", pushData)
                .navigation(this, new NavCallback() {
                    @Override
                    public void onArrival(Postcard postcard) {
                        BusFactory.getBus().post(new Event.pushSkip(pushData));
                        PopupPushActivity.this.finish();
                    }
                });
    }
}
